<!DOCTYPE HTML>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<meta charset="utf-8">
<head th:include="include :: header"></head>
<body class="gray-bg">

<div class="container-div">
    <div class="row">
        <div class="col-sm-12 search-collapse">
            <form id="formId">
                <div class="select-list">
                    <input type="hidden" name="roleKey" id="roleKey" th:value="${role}"/>
                    <ul>
                        <li>
                            大计划id：<input type="text" name="id"/>
                        </li>
                        <li>
                            用户姓名：<input type="text" name="merchantName"/>
                        </li>

                        <li>
                            手机号码：<input type="text" name="merchantPhone"/>
                        </li>

                        <li>
                            A卡号：<input type="text" name="cardNumberA"/>
                        </li>

                        <li>
                            B卡号：<input type="text" name="cardNumberB"/>
                        </li>
                        <li>
                            大计划状态：
                            <input name="params[status]" id="status" type="hidden">
                            <label th:each="role:${@dict.getType('sys_plan_status')}" class="check-box">

                                <input name="status1" id="status1" type="checkbox" th:value="${role.dictValue}"
                                       th:text="${role.dictLabel}">
                            </label>
                        </li>

                        <li>
                            计划类型：<select name="type" th:with="type=${@dict.getType('sys_plan_type')}">
                            <option value="">所有</option>
                            <option th:each="dict : ${type}" th:text="${dict.dictLabel}"
                                    th:value="${dict.dictValue}"></option>
                        </select>
                        <li class="select-time">
                            <label>创建时间： </label>
                            <input type="text" class="time-input" id="beginTime1" placeholder="开始时间"
                                   name="params[beginTime1]"/>
                            <span>-</span>
                            <input type="text" class="time-input" id="endTime1" placeholder="结束时间"
                                   name="params[endTime1]"/>
                        </li>


                        <li>
                            <a class="btn btn-primary btn-rounded btn-sm" onclick="search1()"><i
                                    class="fa fa-search"></i>&nbsp;搜索</a>
                            <a class="btn btn-warning btn-rounded btn-sm" onclick="reset()"><i
                                    class="fa fa-refresh"></i>&nbsp;重置</a>
                        </li>
                    </ul>
                </div>
            </form>
        </div>
        <div class="btn-group-sm hidden-xs" id="toolbar" role="group">
            <a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="system:plan:export">
                <i class="fa fa-download"></i> 导出
            </a>
        </div>
        <div class="col-sm-12 select-table table-striped">
            <table id="bootstrap-table" data-mobile-responsive="true"></table>
        </div>
    </div>
</div>
<div th:include="include :: footer"></div>
<script th:src="@{/js/moment.js}"></script>
<script th:src="@{/ajax/libs/select/select2.js}"></script>
<script th:inline="javascript">
    var editFlag = [[${@permission.hasPermi('system:planNew:edit')}]];
    var prefix = ctx + "system/planNew";

    var datas = [[${@dict.getType('sys_plan_type')}]];
    var data1 = [[${@dict.getType('sys_plan_status')}]];

    function search1() {
        if($("#beginTime1").val()==""||$("#endTime1").val()==""){
            $.modal.alertWarning("请选择创建时间")
        }else {
            var beginTime=$("#beginTime1").val();
            var endTime=$("#endTime1").val();
            var d1 = new Date(beginTime);
            var d2 = new Date(endTime);
            if((parseInt(d2 - d1) / (3600000*24))>31){
                $.modal.alertWarning("时间间隔不能大于一个月")
            }else {
                var test = $("input[name='status1']:checked");
                var checkBoxValue = "";
                test.each(function () {
                    checkBoxValue += $(this).val() + ",";
                })
                checkBoxValue = checkBoxValue.substring(0, checkBoxValue.length - 1);
                $("#status").val(checkBoxValue)
                $.table.search("formId");
            }
        }
    }
    //重置form
    function reset(formId) {
        var test = $("input[name='status1']:checked");
        test.each(function () {
            $(this).parent().removeClass("icheckbox-blue checked");
            $(this).parent().addClass("icheckbox-blue");
        })
        var currentId = $.common.isEmpty(formId) ? $('form').attr('id') : formId;
        $("#" + currentId)[0].reset();
        $("#beginTime1").val((moment(new Date()).subtract(1,'months')).format('YYYY-MM-DD HH:mm:ss') )
        $("#endTime1").val(moment(new Date()).format('YYYY-MM-DD HH:mm:ss') )
    }
    $(function () {
        $("#beginTime1").val((moment(new Date()).subtract(1,'months')).format('YYYY-MM-DD HH:mm:ss') )
        $("#endTime1").val(moment(new Date()).format('YYYY-MM-DD HH:mm:ss') )
    })

    $(function () {
        var options = {
            url: prefix + "/list",
            createUrl: prefix + "/add",
            updateUrl: prefix + "/edit/{id}",
            removeUrl: prefix + "/remove",
            exportUrl: prefix + "/export",
            queryParams: queryParams,
            modalName: "新计划",
            search: false,
            showExport: true,
            columns: [{
                checkbox: true
            },
                {
                    field: 'id',
                    title: '计划编号',
                    align: 'center',
                    formatter: function (value, row, index) {
                        return '<a href="#" onclick="detail(\'' + row.id + '\')">' + value + '</a>';
                    }
                },
                {
                    field: 'merchantName',
                    title: '用户姓名',
                    align: 'center',
                    formatter: function (value, row, index) {
                        return "<strong style='color: mediumslateblue's>" + value + "</strong>";
                    }
                },
                {
                    field: 'merchantPhone',
                    title: '手机号码',
                    align: 'center',
                },
                {
                    field: 'cardNumberA',
                    title: '信用卡号A',
                    align: 'center',
                },
                {
                    field: 'cardNumberB',
                    title: '信用卡号B',
                    align: 'center',
                },
                {
                    field: 'createTime',
                    title: '创建时间',
                    align: 'center',
                },
                {
                    field: 'planAmt',
                    title: '还款金额',
                    align: 'center',
                    formatter: function (value, row, index) {
                        return "<strong style='color: red's>" + value + "</strong>";
                    }
                },
                {
                    field: 'cbAmt',
                    title: '预留金',
                    align: 'center',
                    formatter: function (value, row, index) {
                        return "<strong style='color: blue's>" + value + "</strong>";
                    }
                },
                {
                    field: 'type',
                    title: '计划类型 ',
                    align: 'center',
                    formatter: function (value, row, index) {
                        return $.table.selectDictLabel(datas, value);
                    }
                },

                {
                    field: 'region',
                    title: '地区',
                    align: 'center',
                },
                {
                    field: 'status',
                    title: '计划状态',
                    formatter: function (value, row, index) {
                        return $.table.selectDictLabel(data1, value);
                    }
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function (value, row, index) {
                        var actions = [];
                        if ($("#roleKey").val() != "agent"){
                            actions.push(statusTools(row));
                        }
                        return actions.join('');
                    }
                }]
        };
        $.table.init(options);
    });
        function statusTools(row) {
            //状态(0待执行 1执行中2失败3成功4暂停5删除)

            if (row.status == "0" || row.status == "4" || row.status == "5") {//启用
                return '<a class="btn btn-info btn-xs" href="#" onclick="enable(\'' + row.id + '\')"><i class="fa fa-play"></i>启用</a> ';
            } else if (row.status == "2") {
                return '<a class="btn btn-info btn-xs" href="#" onclick="enable(\'' + row.id + '\')"><i class="fa fa-play"></i>启用</a> ' + '<a class="btn btn-danger btn-xs" href="#" onclick="prohibit(\'' + row.id + '\')")"></i>删除</a>';
            } else if (row.status == "1") {
                return '<a class="btn btn-danger btn-xs" href="#" onclick="prohibit(\'' + row.id + '\')")"></i>删除</a>';
            }


        }

    /*启用*/
    function enable(id) {
        console.log(id);
        $.modal.confirm("确认要启用该计划吗？", function () {
            $.operate.post(prefix + "/updatePlanStatusById", {"id": id, "status": "1"});
        })

    }

    //删除
    function prohibit(id) {
        $.modal.confirm("确认要禁用该计划吗？", function () {
            $.operate.post(prefix + "/updatePlanStatusById", {"id": id, "status": "5"});
        })
    }
    /*跳转计划明细页面*/
    function detail(id) {
        var url = prefix + '/detail/' + id;

        createMenuItem(url, "计划明细详情");
    }

    function queryParams(params) {
        return {
            tradeType: $("#tradeType").val(),
            "params[beginTime1]": $("#beginTime1").val(),
            "params[endTime1]": $("#endTime1").val(),
            pageSize: params.limit,
            pageNum: params.offset / params.limit + 1,
            searchValue: params.search,
            orderByColumn: params.sort,
            isAsc: params.order
        };
    }
</script>
</body>
</html>